<%@include file="parts/Header.jsp" %>
<%--
    Document   : About Us
    Created on : 16/08/2011, 11:47:35 ص
    Author     : Ahmed
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<html:html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Promote Admin</title>

        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

        <style>
            body { font-size: 62.5%; }
            label, input { display:block; }
            input.text { margin-bottom:12px; width:95%; padding: .4em; }
            fieldset { padding:0; border:0; margin-top:25px; }
            h1 { font-size: 1.2em; margin: .6em 0; }
            div#users-contain { width: auto; margin: 20px 0; }
            div#users-contain table { margin: 1em 0; border-collapse: separate; width: 100%; }
            div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
            .ui-dialog .ui-state-error { padding: .3em; }
            .validateTips { border: 1px solid transparent; padding: 0.3em; }
        </style>
        <script>
            
            $(function() {
                var name = $( "#name" ),
                email = $( "#email" ),
                password = $( "#password" ),
                allFields = $( [] ).add( name ).add( email ).add( password ),
                tips = $( ".validateTips" );
 
                function updateTips( t ) {
                    tips
                    .text( t )
                    .addClass( "ui-state-highlight" );
                    setTimeout(function() {
                        tips.removeClass( "ui-state-highlight", 1500 );
                    }, 500 );
                }
 
                function checkLength( o, n, min, max ) {
                    if ( o.val().length > max || o.val().length < min ) {
                        o.addClass( "ui-state-error" );
                        updateTips( "Length of " + n + " must be between " +
                            min + " and " + max + "." );
                        return false;
                    } else {
                        return true;
                    }
                }
 
                function checkRegexp( o, regexp, n ) {
                    if ( !( regexp.test( o.val() ) ) ) {
                        o.addClass( "ui-state-error" );
                        updateTips( n );
                        return false;
                    } else {
                        return true;
                    }
                }
 
                $( "#dialog-form" ).dialog({
                    autoOpen: false,
                    height: 500,
                    width: 350,
                    modal: true
                   
                });
 
                $( "#create-user" )
                .button()
                .click(function() {
                    $( "#dialog-form" ).dialog( "open" );
                });
            });
            
            
             
        </script>
        <style type="text/css">
            .js #dialog-form {display: none;}

        </style>
        <script type="text/javascript">
            document.documentElement.className = 'js';
        </script>
    </head>
    <body onload="resizePage()">
        <center>
            <div id="innerPageContainer" >
                <table  cellpadding="0" cellspacing="0" border="0">
                    <tr>

                        <td rowspan="3" id="innerPageCell" >

                            <div  id="accordion" >



                                <div id="dialog-form" title="Add Admin">
                                    <img src="styles/Images/logo2.gif"/>
                                    <p class="validateTips">All form fields are required.</p>

                                    <html:form action="/admin?actionType=addAdmin">
                                        <fieldset>
                                            <label for="name">Admin name</label>
                                            <html:text styleId="adminName" property="adminName"  styleClass="text ui-widget-content ui-corner-all" />
                                            <label for="name">Admin Email</label>
                                            <html:text styleId="adminEmail" property="adminEmail"  styleClass="text ui-widget-content ui-corner-all" />

                                            <label for="name">Admin Password</label>
                                            <html:password styleId="adminPassword" property="adminPassword"  styleClass="text ui-widget-content ui-corner-all" />
                                            <html:hidden property="createdBy" value="${admin.adminId}"/>
                                            <div id="div1"></div>
                                        </fieldset>
                                        <html:submit onclick="return validate()" style="margin-bottom:12px; width:100%; padding: .4em;border-bottom:1px solid;padding:0!important;background:none!important;border:none"  value="Add"/>
                                    </html:form>


                                    <center> 

                                    </center>



                                </div>

                                <script>
                                    function validate(){
                                        var sn=document.getElementById('adminName').value;
                                        var miu=document.getElementById('adminEmail').value;
                                        var ssd=document.getElementById('adminPassword').value;
                                        
                                        if(sn.length<1){
                                            document.getElementById('div1').innerHTML='<font color=red>Admin name  can\'t be Empty</font>';
                                            return false
                                        }
                                        else{
                                            document.getElementById('div1').innerHTML='';
                        
                                        }
                                        if(miu.length<1){
                                            document.getElementById('div1').innerHTML='<font color=red>Admin Email can\'t be Empty</font>';
                                            return false
                                        }
                                        else{
                                            document.getElementById('div1').innerHTML='';
                            
                                        }
                                        if(ssd.length<1){
                                            document.getElementById('div1').innerHTML='<font color=red>Admin Password Must be provided</font>';
                                            return false
                                        }
                                        else{
                                            document.getElementById('div1').innerHTML='';
                            
                                        }
                                        if(dp.length<1){
                                            document.getElementById('div1').innerHTML='<font color=red>Due Date Must be provided</font>';
                                            return false
                                        }
                                        else{
                                            document.getElementById('div1').innerHTML='';
                            
                                        }
                            
                                    }
                                </script>



                                <div id="users-contain" class="ui-widget">

                                    <table id="users" style="alignment-adjust: central" class="ui-widget ui-widget-content">
                                        <thead>
                                            <tr class="ui-widget-header ">
                                                <th>Admin Id</th>
                                                <th>Admin Name</th>
                                                <th>Admin Email</th>
                                                <th>Created By</th>
                                                <th>Priviledges</th>
                                                <th>Remove Privilege</th>
                                                <th>Add Privilege</th>
                                                <th>Delete Admin</th>

                                            </tr>
                                        </thead>
                                        <tbody>

                                            <logic:iterate name="AdminBean" property="admins" id="msg">
                                                <tr>
                                                    <html:form action="/admin?actionType=deletePriv">

                                                        <html:hidden value="${msg.adminId}" property="adminId" />
                                                        <td><bean:write name="msg" property="adminId"/></td>
                                                        <td><html:text size="10" value="${msg.adminName}" property="adminName"/></td>
                                                        <td><html:text size="20" value="${msg.adminEmail}" property="adminEmail"/></td>
                                                        <td><html:text size="3" value="${msg.createdBy}" property="createdBy"/></td>
                                                        <td>
                                                            <html:select name="AdminBean" property="privilegeId">
                                                                <logic:iterate name="msg" property="privilegeses" id="p">

                                                                    <html:option value="${p.privilegeId}">${p.privilegeName}</html:option>

                                                                </logic:iterate>
                                                            </html:select>
                                                        </td>
                                                        <td>
                                                            <html:submit style="margin-bottom:12px; width:100%; padding: .4em;border-bottom:1px solid;padding:0!important;background:none!important;border:none"  value="Remove Privilege"/></td>
                                                        <td>
                                                        </html:form>
                                                        <html:form action="/admin?actionType=addPriv">
                                                            <html:hidden value="${msg.adminId}" property="adminId" />
                                                            <html:select name="AdminBean" property="privilegeId">
                                                                <logic:iterate name="AdminBean" property="privi" id="p">
                                                                    <html:option value="${p.privilegeId}">${p.privilegeName}</html:option>
                                                                </logic:iterate>
                                                            </html:select>
                                                            <html:submit style="margin-bottom:12px; width:100%; padding: .4em;border-bottom:1px solid;padding:0!important;background:none!important;border:none"  value="Add Privilege"/>
                                                        </html:form>

                                                    </td>

                                                    <td><html:link  action="/admin?actionType=deleteAdmin" paramId="adminId"  paramName="msg" paramProperty="adminId">Delete Admin</html:link></td>
                                                </tr>
                                            </logic:iterate>

                                        </tbody>
                                    </table>
                                </div>




                            </div>
                            <button id="create-user">Add new Admin</button>
                        </td>
                    </tr>

                    <tr>

                    </tr>

                    <tr>

                    </tr>

                    <tr>
                        <td colspan="2" class="footer">
                            <jsp:include page="parts/Footer.jsp"/>
                        </td>
                    </tr>
                </table>

            </div>
        </center>
    </body>
</html:html>

